#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <assert.h>
#define     LEN     1024
void *memcpy1(void *dest, const void *src, size_t n);

int main(int argc, char* argv[])
{
    int t = atol(argv[1]);

    void* dest = malloc(t);
    void* src = malloc(t);

    struct timeval tvs;
    struct timeval tve;

    int i;
    double sec;

    memset(dest, 1, t);
    memset(src, 0, t);
    gettimeofday(&tvs, NULL);
    for(i=1; i<=t; i++) {
        memcpy(dest, src, i);
    }
    gettimeofday(&tve, NULL);
    sec = (double)(tve.tv_sec - tvs.tv_sec)
    + (double)(tve.tv_usec - tvs.tv_usec)/(double)1000000.0;
    printf("%lf\n", sec);

    memset(dest, 1, t);
    memset(src, 0, t);
    gettimeofday(&tvs, NULL);
    for(i=1; i<=t; i++) {
        memcpy1(dest, src, i);
    }
    gettimeofday(&tve, NULL);
    sec = (double)(tve.tv_sec - tvs.tv_sec)
    + (double)(tve.tv_usec - tvs.tv_usec)/(double)1000000.0;
    printf("%lf\n", sec);


    return 0;
}


void *memcpy1(void *dest, const void *src, size_t n)
{
    int i;
    int t = n / 8;
    for(i=0; i<t; i++) {
        *(long long*)(dest+(i<<3)) = *(long long*)(src+(i<<3));
    }

#if 0
    for(i=(t<<3);i<n; i++) {
        *(char*)(dest+(i)) = *(char*)(src+(i));
    }
#endif

    //assert(0 == memcmp(dest, src, n));

    return dest;
}

